"""
The Wizard which initializes the state variables for the owner of the
KuplaMail Instance.
Written by: Daniel Ortiz
Date: Oct 27 2007
"""

import wx
import wx.wizard

class OwnerPage(wx.wizard.WizardPageSimple):
    """The Owner Page asks the user for global control features."""
    def __init__(self, parent):
        """Constructs a simple page to initialze the owner"""
        wx.wizard.WizardPageSimple.__init__(self, parent)
        self.sizer = wx.GridBagSizer(hgap = 1, vgap = 1)

        title = wx.StaticText(self, -1, 'Owner')
        title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
        owner = wx.StaticText(self, -1, 'Name: ')
        self.owner_text = wx.TextCtrl(self, -1)
        self.password_text = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD)
        self.pass_text = wx.StaticText(self, -1, 'Password: ')
        self.multiple_users = wx.CheckBox(self, -1, 'Multiple Users')
        self.sc_arch = wx.CheckBox(self, -1, 'Portal')
        self.password = wx.CheckBox(self, -1, 'Password Protected')
        self.password.SetValue(True)
        self.password.Bind(wx.EVT_CHECKBOX, self.OnCheck)

        # Add to sizer
        self.sizer.Add(title, pos = (0, 0), span = (1, 4),
                       flag = wx.ALIGN_CENTER)
        self.sizer.Add(owner, pos = (2, 0))
        self.sizer.Add(self.owner_text, pos = (2, 1), span = (1, 3),
                       flag = wx.EXPAND)
        self.sizer.Add(self.multiple_users, pos = (4, 1))
        self.sizer.Add(self.sc_arch, pos = (5, 1))
        self.sizer.Add(self.password, pos = (6, 1))
        self.sizer.Add(self.pass_text, pos = (8, 0))
        self.sizer.Add(self.password_text, pos = (8, 1), span = (1, 3),
                       flag = wx.EXPAND)

        self.sizer.AddGrowableCol(0)
        self.sizer.AddGrowableCol(1)
        self.sizer.AddGrowableCol(2)
        self.sizer.AddGrowableCol(3)
        self.SetSizer(self.sizer)

    def OnCheck(self, event):
        """
        Upon a toggle of the check for password protected, a password
        box will open for user input.
        """
        if self.password.GetValue():
            self.sizer.Show(self.pass_text)
            self.sizer.Show(self.password_text)
        else:
            self.sizer.Hide(self.pass_text)
            self.sizer.Hide(self.password_text)

    def GetValue(self):
        """Get the value of all the references"""
        return [self.owner_text.GetValue(), self.multiple_users.GetValue(),
                self.sc_arch.GetValue(), self.password.GetValue(),
                self.password_text.GetValue()]

class MailboxPage(wx.wizard.WizardPageSimple):
    """The Mailbox Page specifies the first mailbox of the user"""
    def __init__(self, parent):
        """Initialize the first mailbox"""
        wx.wizard.WizardPageSimple.__init__(self, parent)
        self.sizer = wx.GridBagSizer(hgap = 1, vgap = 1)

        title = wx.StaticText(self, -1, 'Mailbox')
        title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
        name = wx.StaticText(self, -1, 'Name:')
        self.name_text = wx.TextCtrl(self, -1)

        username = wx.StaticText(self, -1, 'Username:')
        self.username_text = wx.TextCtrl(self, -1)

        mailserver = wx.StaticText(self, -1, 'Domain:')
        self.mailserver_text = wx.TextCtrl(self, -1)
        
        password = wx.StaticText(self, -1, 'Password:')
        self.password_text = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD)

        self.private = wx.CheckBox(self, -1, 'Private')
        self.private.SetValue(True)
        
        self.sizer.Add(title, pos = (0, 0), span = (1, 4),
                       flag = wx.ALIGN_CENTER)

        self.sizer.Add(name, pos = (2, 0))
        self.sizer.Add(self.name_text, pos = (2, 1), span = (1, 3),
                       flag = wx.EXPAND)
        self.sizer.Add(username, pos = (4, 0))
        self.sizer.Add(self.username_text, pos = (4, 1), span = (1, 3),
                       flag = wx.EXPAND)
        self.sizer.Add(mailserver, pos = (6, 0))
        self.sizer.Add(self.mailserver_text, pos = (6, 1), span = (1, 3),
                       flag = wx.EXPAND)
        self.sizer.Add(password, pos = (8, 0))
        self.sizer.Add(self.password_text, pos = (8, 1), span = (1, 3),
                       flag = wx.EXPAND)

        self.sizer.Add(self.private, pos = (10, 1))

        self.sizer.AddGrowableCol(0)
        self.sizer.AddGrowableCol(1)
        self.sizer.AddGrowableCol(2)
        self.sizer.AddGrowableCol(3)
        self.SetSizer(self.sizer)

    def GetValue(self):
        """Get the value of the mailbox variables"""
        return [self.username_text.GetValue(), self.mailserver_text.GetValue(),
                self.password_text.GetValue(), self.name_text.GetValue(),
                self.private.GetValue()]

class SetupWizard(wx.wizard.Wizard):
    """Wizard class which encapsulates the data inputted from the
    wizardSimplePages"""
    def __init__(self, parent, name):
        wx.wizard.Wizard.__init__(self, parent, -1, name)
        self.CenterOnParent()
        self.page1 = OwnerPage(self)
        self.FitToPage(self.page1)

    def run(self):
        """Run the wizard and get the return the relevant data"""
        if self.RunWizard(self.page1):
            return [self.page1.GetValue()]
        
if __name__ == '__main__':
    """Testing the setup applications"""
    app = wx.PySimpleApp()
    wizard = SetupWizard(None, 'Setup Test')
    values = wizard.run()
    wizard.Destroy()
    print values
